import { defineStore } from "pinia";
import { ref, computed } from "vue";
import axios from "axios";
export const useCounterStore = defineStore('counter',()=> {
    //定义数据
    const count = ref(0);

    //定义方法
    const increment = () => {
        count.value++;
    }
    //getters
    const doubleCount = computed(() => count.value * 2);

    //异步action
    const list = ref([]);

    const fetchList = async () => {
        const res = await axios.get('https://jsonplaceholder.typicode.com/todos');
        console.log(res);
        //赋值list
        list.value = res.data;
    }
    return {
        count,
        increment,
        doubleCount,
        list,
        fetchList
    }
});